/*
@Copyright:LintCode
@Author:   tjyemail
@Problem:  http://www.lintcode.com/problem/plus-one
@Language: C++
@Datetime: 16-02-09 05:14
*/

class Solution {
public:
    /**
     * @param digits a number represented as an array of digits
     * @return the result
     */
    vector<int> plusOne(vector<int>& digits) {
        // Write your code here
        int carry=1;
        for(int i=digits.size()-1;i>=0 && carry;--i){
            digits[i]+=carry;
            carry = digits[i]/10;
            digits[i]%=10;
        }
        if (carry)
            digits.insert(digits.begin(),carry);
        return digits;
    }
};